// 菜单调试工具
export const debugMenu = {
  // 打印当前菜单结构
  printMenuStructure(menuItems, level = 0) {
    const indent = '  '.repeat(level);
    menuItems.forEach(item => {
      console.log(`${indent}${item.key}: ${item.title} (${item.path || 'no path'})`);
      if (item.children) {
        this.printMenuStructure(item.children, level + 1);
      }
    });
  },

  // 检查路径匹配
  checkPathMatch(currentPath, menuItems) {
    console.log('当前路径:', currentPath);
    console.log('菜单结构:');
    this.printMenuStructure(menuItems);
    
    // 查找匹配的菜单项
    const findMatches = (items, path, parentKey = '') => {
      items.forEach(item => {
        const fullKey = parentKey ? `${parentKey}.${item.key}` : item.key;
        if (item.path) {
          const itemPath = item.path.startsWith('/') ? item.path : '/' + item.path;
          const currentPathNormalized = path.startsWith('/') ? path : '/' + path;
          
          const isMatch = itemPath === currentPathNormalized || 
                         currentPathNormalized.startsWith(itemPath + '/');
          
          console.log(`检查 ${fullKey}: ${itemPath} vs ${currentPathNormalized} = ${isMatch}`);
        }
        
        if (item.children) {
          findMatches(item.children, path, fullKey);
        }
      });
    };
    
    findMatches(menuItems, currentPath);
  },

  // 测试菜单高亮
  testMenuHighlight(menuItems, testPaths) {
    console.log('=== 菜单高亮测试 ===');
    testPaths.forEach(path => {
      console.log(`\n测试路径: ${path}`);
      this.checkPathMatch(path, menuItems);
    });
  }
};

// 在开发环境中添加到全局
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
  window.debugMenu = debugMenu;
  console.log('🔧 菜单调试工具已加载: window.debugMenu');
}
